<template>
    <div class="article">
      <div class="item" 
      @click="$router.push({path: '/detail', query: { id: item.id }})"
      v-for="item in list" :key="item.id" >
        <div class="top">
          <!-- <div class="left">1</div> -->
          <img :src="item.creatorAvatar" alt="" />
          <div class="right">
            <div class="title">{{ item.stem }}</div>
            <div class="username">
              <span>{{ item.creatorName }}</span>
              <span>|</span>
              <span>{{ item.createdAt }}</span>
            </div>
          </div>
        </div>
        <div class="middle">
          {{ item.content }}
        </div>
        <div class="bottom">
          <span>点赞 {{ item.likeCount }}</span>
          <span>|</span>
          <span>浏览 {{ item.views }}</span>
        </div>
      </div>
    </div>
  </template>
  <!-- 引入在线axios -->

  <script>
  import axios from 'axios';
  export default {
    name: 'HmArticle',
    data() {
      return {
        list: []
      }
    },
    mounted() {
        this.getList()
    },
    methods: {
      async getList() {
        axios.get('https://mock.boxuegu.com/mock/3083/articles').then(res => {
          console.log(res.data.result.rows);
          this.list = res.data.result.rows;
          if(this.$route.query.isNew){
            // 按时间排序数组    
            this.list.sort(() => {
              return -1;
            });
          }
        })
      }
    }
  }
  </script>
  
  <style lang="less" scoped>
  .item {
    border: 1px solid #000;
    .top {
      display: flex;
  
      img {
        width: 50px;
        height: 50px;
        border-radius: 50%;
      }
  
      .right {
        flex: 1;
      }
    }
  }
  // 超过两行显示省略号
  .middle {
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }
  </style>